// pages/kucun/kucun.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {},
  submit: function(e) {
    console.log(e.detail.value);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var zid = options.zid
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.setData({
      zid: zid
    })
    this.getMymembsite()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  submit: function(e) {
    var that = this
    var id = that.data.id
    if (!id) {
      var op = 'insert'
    } else {
      var op = 'edit'
    }
    var values = e.detail.value
    var fwtime = values.fwtime
    var kucun = values.kucun
    var moremoney = values.moremoney
    var nowprice = values.nowprice
    var num = values.num
    var price = values.price
    var state = that.data.state
    app.util.request({
      'url': 'entry/wxapp/Svdocmember',
      data: {
        fwtime: fwtime,
        kucun: kucun,
        moremoney: moremoney,
        nowprice: nowprice,
        num: num,
        price: price,
        zid: that.data.zid,
        openid: wx.getStorageSync('openid'),
        op: op,
        state: state
      },
      success(res) {
        wx.showToast({
          title: '编辑成功',
          icon: 'none',
          duration: 1500,
          success: function(res) {
            setTimeout(function() {
              wx.navigateBack({
                detail: 1
              })
            }, 1500)
          }
        })

      }
    })
  },
  //查询一条记录
  getMymembsite() {
    var that = this
    var zid = that.data.zid
    var openid = wx.getStorageSync('openid')
    app.util.request({
      'url': 'entry/wxapp/Svdocmember',
      data: {
        zid: zid,
        openid: openid,
        op: 'select'
      },
      success: function(res) {
        console.log(res)
        that.setData({
          id: res.data.id,
          msg: res.data
        })
      }
    })
  },
  kt(e) {
    var that = this
    var values = e.detail.value
    if (values) {
      var state = 1
      console.log('1')
    } else {
      var state = 0
      console.log('0')
    }
    that.setData({
      state: state
    })
  }
})